<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php 
$ci = & get_instance();
$ci->load->library('country_city');
//echo $phpJS; 

?>

<form action="<?php echo site_url('buyer/shows/submit_edit_bid');?>" name="submit_edit_bid" id="submit_edit_bid" method="post" enctype="multipart/form-data" >
	<input type="hidden" name="ref_no" id="ref_no" value="<?php echo $_GET['ref_no'];?>" />
	<input type="hidden" name="scrid" id="scrid" value="<?php echo $_GET['scrid'];?>" />

	<div id="center-wrap" class="ui-corner-tl ui-corner-tr">
		<div id="navigation" class="ui-corner-all"><ul><?php echo $navigator;?></ul></div>
		<div class="clrboth"></div>
	
		<div class="row" id="booking_zone">
			<?php 
				$booking = $items['booking'];
				$bid = $items['bid'];
				$SHOW = $ci->show_entity->init('ref_no',$bid->getShowRefNo());
				$i = 1;
				foreach($booking as $item_obj):
			?>
			<?php 
				$book = $this->booking_entity->init('id',$item_obj->id);
				$style= $i > 1 ? 'style="margin-top:25px;"' : '';
			?>
			<div class="clrboth"></div>
			<div class="column grid_9 items" id="id_<?php echo $i;?>" <?php echo $style;?> >
				<div class="column grid_2">Booking for:</div>
				<div class="column grid_6" id="zone_slb">
					<?php 
						echo form_dropdown( 'booking_for[]',
											$options = countryZoneDataConfig(),
											$selected = array($book->getBookingFor()),
											"id='booking_for[]' class='width270' onchange='changeZone(\"id_$i\",this.value);' "
										);	
					?>
				</div>
				<div class="clrboth"></div>
				
				<div class="column grid_2">Country:</div>
				<div class="column grid_6" id="country_slb">
					<?php 
						$country_records = $ci->country_city->getCountryRecordsBy_zonecode($book->getBookingFor());
						$options = array();
						foreach($country_records as $record){
							$options[$record->id] = $record->name;
						}
						echo form_dropdown( 'country[]',
											$options,
											$selected = array($book->getCountry()),
											"id='country[]' class='width270' onchange='changeCountry(\"id_1\",this.value);' "
										);	
					?>
				</div>
				<div class="clrboth"></div>
				
				<div class="column grid_2">City:</div>
				<div class="column grid_6" id="city_slb">
					<?php 
						$city_records = $ci->country_city->getCityRecordsBy_countryid($book->getCountry());
						$options = array();
						foreach($city_records as $record){
							$options[$record->id] = $record->name;
						}
						echo form_dropdown( 'city[]',
											$options,
											$selected = array($book->getCity()),
											"id='city[]' class='width270'"
										);	
					?>
				</div>
				
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Venue:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="200" name="venue[]" id="venue_1" value="<?php echo $book->getVenue();?>" class="inputText" class="required" />
				</div>
				
				<div class="clrboth"></div>
			
				<div class="column grid_2">
					Address:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="200" name="address[]" id="address_1" value="<?php echo $book->getAddress();?>" class="inputText" class="required" />
				</div>
					
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Capacity:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="200" name="capacity[]" id="capacity_1" value="<?php echo $book->getCapacity();?>" class="inputText" class="required" />
				</div>
					
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Ticket Pricing:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="200" name="ticket_pricing[]" id="ticket_pricing_1" value="<?php echo $book->getTicketPrice();?>" class="inputText" class="required" />
				</div>
					
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Potential Sponsors:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="200" name="potential_sponsors[]" id="potential_sponsors_1" value="<?php echo $book->getPotentialSponsors();?>" class="inputText" class="required" />
				</div>
				
				<?php if($i >1) :?>
					<div class="clrboth"></div>
					<?php if($SHOW->getStatus() == 'opening'):?>		
						<div class="column grid_2">
							&nbsp;
						</div>
						<div class="column grid_6">
							<input type="button" value="Remove" id="remove_booking_item" name="remove_booking_item" class="ui-corner-all button-yellow removeitem2" onclick="removeItem(<?php echo $i;?>,<?php echo $book->getId();?>);" rel="id_<?php echo $i;?>" />
							&nbsp;	&nbsp;&nbsp;
							<?php echo loader_image(" class='hidden' id='remove_booking_item_$i' ");?>
						</div>
					<?php endif;?>	
				<?php endif;?>	
				<div class="clrboth"></div>
				<input type="hidden" name="edit_id[]" id="edit_id[]" value="<?php echo $book->getId();?>" />
				
			</div>
				<?php $i++;?>
			<?php endforeach;?>	
			<div class="clrboth"></div>
		</div>
	
		<div class="clrboth"></div>
		<input type="hidden" name="bid_id" id="bid_id" value="<?php echo $bid->getId();?>" />
		<div class="row">	
			<?php if($SHOW->getStatus() == 'opening'):?>	
				<div class="column grid_9">
					<div class="column grid_6">
						<input type="button" value="Add a city" class="add_a_city" id="add_a_city" name="add_a_city" onclick="addACity();" />
						&nbsp;	&nbsp;&nbsp;
						<?php echo loader_image(" class='hidden' id='loader_add_a_city' ");?>
					</div>
					<div class="clrboth"></div>
				</div>
			<?php else:?>
				<div class="clrboth" style="height:30px;"></div>
			<?php endif;?>	
			<div class="clrboth"></div>
		
			<div class="column grid_9">	
				<div class="clrboth"></div>	
				
				<div class="column grid_2">
					Offer Price:
				</div>
				<div class="column grid_6">
					<input type="text" maxlength="20" name="offer_price" id="offer_price" value="<?php echo $bid->getOfferPrice();?>" class="inputText" class="required" />&nbsp;&nbsp; USD
				</div>
					
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Promoter History:
				</div>
				<div class="column grid_6">
					<table cellspacing="3">
						<tr>
							<td width="60px">Artist/Production</td>
							<td width="30px">Year</td>
							<td width="50px">Capacity</td>
							<td width="30px">Venue</td>
						</tr>
				
						<tr>
							<td><input type="text" name="artist_production1" id="artist_production1" value="<?php echo $bid->getArtistProduction1();?>" maxlength="200" style="width:120px;" class="in-tbl"/></td>
							<td><input type="text" name="year1" id="year1" value="<?php echo $bid->getYear1();?>" maxlength="6" style="width:70px;" class="in-tbl"/></td>
							<td><input type="text" name="capacity1" id="capacity1" value="<?php echo $bid->getCapacity1();?>" maxlength="200" style="width:100px;" class="in-tbl"/></td>
							<td><input type="text" name="venue1" id="venue1" value="<?php echo $bid->getVenue1();?>" maxlength="200" style="width:70px;" class="in-tbl"/></td>
						</tr>
						
						<tr>
							<td><input type="text" name="artist_production2" id="artist_production2" value="<?php echo $bid->getArtistProduction2();?>" maxlength="200" style="width:120px;" class="in-tbl"/></td>
							<td><input type="text" name="year2" id="year2" value="<?php echo $bid->getYear2();?>" maxlength="6" style="width:70px;" class="in-tbl"/></td>
							<td><input type="text" name="capacity2" id="capacity2" value="<?php echo $bid->getCapacity2();?>" maxlength="200" style="width:100px;" class="in-tbl"/></td>
							<td><input type="text" name="venue2" id="venue2" value="<?php echo $bid->getVenue2();?>" maxlength="200" style="width:70px;" class="in-tbl"/></td>
						</tr>
						
						<tr>
							<td><input type="text" name="artist_production3" id="artist_production3" value="<?php echo $bid->getArtistProduction3();?>" maxlength="200" style="width:120px;" class="in-tbl"/></td>
							<td><input type="text" name="year3" id="year3" value="<?php echo $bid->getYear3();?>" maxlength="6" style="width:70px;" class="in-tbl"/></td>
							<td><input type="text" name="capacity3" id="capacity3" value="<?php echo $bid->getCapacity3();?>" maxlength="200" style="width:100px;" class="in-tbl"/></td>
							<td><input type="text" name="venue3" id="venue3" value="<?php echo $bid->getVenue3();?>" maxlength="200" style="width:70px;" class="in-tbl"/></td>
						</tr>
						
						<tr>
							<td><input type="text" name="artist_production4" id="artist_production4" value="<?php echo $bid->getArtistProduction4();?>" maxlength="200" style="width:120px;" class="in-tbl"/></td>
							<td><input type="text" name="year4" id="year4" value="<?php echo $bid->getYear4();?>" maxlength="6" style="width:70px;" class="in-tbl"/></td>
							<td><input type="text" name="capacity4" id="capacity4" value="<?php echo $bid->getCapacity4();?>" maxlength="200" style="width:100px;" class="in-tbl"/></td>
							<td><input type="text" name="venue4" id="venue4" value="<?php echo $bid->getVenue4();?>" maxlength="200" style="width:70px;" class="in-tbl"/></td>
						</tr>
						
					</table>
				</div>
					
				<div class="clrboth"></div>
				
				<div class="column grid_2">
					Term and Conditions:
				</div>
				<div class="column grid_4">
					<input type="checkbox" name="agree_term_n_conditional" id="agree_term_n_conditional" checked="checked" onclick="agree_term(this.checked);" /> 
					&nbsp;&nbsp; 
					<a href="javascript:void(0);" onclick="openTermAndConditional();" >I agree of this term and conditions.</a>
				</div>
				
				<div class="clrboth"></div>
			
				
			</div>
			<div class="clrboth"></div>
		<?php if($SHOW->getStatus() == 'opening'):?>	
			<div class="column grid_9" id="after_agreement" style="margin-top:30px;">	
				<div class="clrboth"></div>	
				<div class="column grid_2">
					&nbsp;
				</div>
				<div class="column grid_2">
					<input type="submit" id="submit_bid" name="submit_bid" value="Submit Bid" class="ui-corner-all button-yellow" />
					&nbsp;	&nbsp;&nbsp;
					<?php echo loader_image(" class='hidden' id='submit_bid_loader' ");?>
					<div class="clrboth"></div>	
					<span id="submit_bid_error" class="red hidden">Please fill require fields input.</span>
				</div>
				
				<div class="column grid_2">
					<input type="button" id="ask_seller_question" onclick="openDialogAskQuestion();" name="ask_seller_question" value="Ask Seller a Question" class="ui-corner-all button-yellow" />
					<div class="clrboth"></div>	
					<span id="ask_seller_question_stt" class="green hidden">Sent message.</span>
				</div>
			</div>
			<div class="clrboth"></div>
		<?php endif; ?>	
		</div>
	
	 
		<div id="term_and_conditional" title="Term and conditions" class="hidden" style="padding:10px 30px;">
			{pyro:getpost:body id="22"}	
		</div>

		<div id="ask_question" title="Ask Seller a Question" class="hidden" style="padding:10px 30px;">
			<div class="column grid_2">Subject:</div>
			<div class="column grid_4"><input type="text" name="subject" id="subject" value="" maxlength="200" style="width:350px;" /></div>
			
			<div class="clrboth"></div>
			
			<div class="column grid_2">Message:</div>
			<div class="column grid_4"><textarea name="message" id="message" style="width:350px;height:200px;"></textarea></div>
			
			<div class="clrboth"></div>
			
			<div class="column grid_2" style="margin-top:20px;">
				<input type="button" id="submit_question" name="submit_question" onclick="submitQuestion();" value="Submit Question" class="ui-corner-all button-yellow" />
			</div>
		</div>
 
	</div>
</form>		
<div class="clrboth"></div>



<script type="text/javascript">
	$(document).ready(function() {
		if($('#agree_term_n_conditional').attr('checked')){
			$('#after_agreement').show();
		}else{
			$('#after_agreement').hide();
		}	
		
	});
	
	function agree_term(checked){
		if(checked){
			$('#after_agreement').show();
		}else{
			$('#after_agreement').hide();
		}
	}
	
	function openTermAndConditional(){
		$('#term_and_conditional').dialog(
			{
				 width: 1000,
				 resizable: false,
				 height:550,
			}
		);
	}
	
	function openDialogAskQuestion(){
		$('#ask_question').dialog(
			{
				 width: 500,
				 resizable: false,
				 height:400,
			}
		);
	}
	
	function submitQuestion(){
		$.post(BASE_URI+"buyer/shows/submitQuestionSeller",{subject:$('#subject').val(),message:$('#message').val(),ref_no:$('#ref_no').val()},function(response){
			if(response == 'ok'){
				$('#ask_question').dialog( 'close');
				$('#ask_seller_question_stt').show();
			}
		});
	}
	
	function changeZone(positionId, value){
		$.post(BASE_URI+"buyer/shows/ajax_changeZone",{value:value,positionId:positionId},function(response){
			$('#'+positionId+" #country_slb").html(response);
			var firstValue = $('#'+positionId+" #country_slb select").val();
			changeCountry(positionId, firstValue);
		});
	}
	
	function changeCountry(positionId, value){
		$.post(BASE_URI+"buyer/shows/ajax_changeCountry",{value:value,positionId:positionId},function(response){
			$('#'+positionId+" #city_slb").html(response);
		});
	}
	
	function addACity(){
		$('#loader_add_a_city').removeClass("hidden");
		var currentItem = $('#booking_zone .items').size();
		
		$.post(BASE_URI+"buyer/shows/ajax_addBookingfor",{currentItem:currentItem},function(response){
			$("#booking_zone").append(response);
			$('#loader_add_a_city').addClass("hidden");
		});
	}

	function removeItem($position_id, $item_id){	
		$("#booking_zone #id_"+ $position_id).remove();	
	}
	
	google.setOnLoadCallback(function() {
		$('.removeitem').live('click',function(){
			$id= $(this).attr('rel');
			$("#booking_zone #"+ $id).remove();
		});
	});
	

</script>
